package com.gange.controller;

import com.gange.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
@Slf4j
public class UploadController {
    @PostMapping("/upload")
    public Result upload(MultipartFile image){
        //获取到客户端上传图片的图片名
        String originalFilename = image.getOriginalFilename();
        log.info("originalFilename:{}",originalFilename);

        UUID.randomUUID().toString();

        try {
            //把客户端传递的图片复制到相应位置
            image.transferTo(new File("d:/"+originalFilename));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return Result.success();
    }
}
